#+TITLE: Elixir IDE
#+AUTHOR: Zelphir Kaltstahl
#+STARTUP: content
#+STARTUP: indent
#+STARTUP: align
#+STARTUP: inlineimages
#+STARTUP: hideblocks
#+STARTUP: entitiesplain
#+STARTUP: nologdone
#+STARTUP: nologreschedule
#+STARTUP: nologredeadline
#+STARTUP: nologrefile
#+TODO: TODO INPROGRESS UNCLEAR | DONE CANCELLED
#+DATE: [2023-11-30 Thu]
#+LANGUAGE: English
#+PRIORITIES: A E E
#+KEYWORDS: emacs config elixir ide features lsp linter checker flycheck

* Create release of =elixir-ls=
:PROPERTIES:
:CUSTOM_ID: elixir-ls-release
:END:

#+begin_src sh
git clone https://github.com/elixir-lsp/elixir-ls.git elixir-ls
pushd elixir-ls
git checkout v0.17.10  # or some other release
mix deps.get
MIX_ENV=prod mix compile
MIX_ENV=prod mix elixir_ls.release2 -o release
popd
#+end_src

Then a language server script file should have been created under =elixir-ls/release/language_server.sh=.

* Emacs configuration
:PROPERTIES:
:CUSTOM_ID: emacs-configuration
:END:

** Elixir
:PROPERTIES:
:CUSTOM_ID: emacs-configuration-elixir
:END:

Add the following things to your =init.el=:

#+begin_src elisp
(use-package elixir-mode :ensure t)
(use-package alchemist :ensure t)
#+end_src

** Eglot
:PROPERTIES:
:CUSTOM_ID: emacs-configuration-eglot
:END:

#+begin_src elisp
;;; LSP
(require 'eglot)
;; This is optional.  It automatically runs `M-x eglot` for
;; you whenever you are in `elixir-mode`
(add-hook 'elixir-mode-hook 'eglot-ensure)
(add-to-list 'eglot-server-programs
             `(elixir-mode "~/.guix-extra-profiles/emacs-env/elixir-ls/release/language_server.sh"))
#+end_src

** Company
:PROPERTIES:
:CUSTOM_ID: emacs-configuration-company
:END:

Some configuration that makes company run and a few shortcuts.

#+begin_src elisp
(use-package company
  :ensure t
  :init
  (setq company-show-numbers t)
  (setq company-idle-delay t)
  (setq company-require-match nil)
  (setq company-tooltip-idle-delay nil)
  (setq company-tooltip-maximum-width 120)
  (setq company-tooltip-minimum 3)
  (setq company-tooltip-align-annotations t)
  :config
  (define-key company-mode-map (kbd "C-<return>") 'company-complete)
  (define-key company-active-map (kbd "C-n") 'company-select-next)
  (define-key company-active-map (kbd "C-p") 'company-select-previous)
  )
#+end_src
